using System.Windows;

namespace FireUI.Themes.Core;

public class ThemeManager : IThemeManager
{
    private IDictionary<string, ResourceDictionary> _themes;

    public ThemeManager()
    {
        _themes = new Dictionary<string, ResourceDictionary>
        {
            {
                "DeepDark",
                new ResourceDictionary
                {
                    Source = new Uri(
                        @"/FireUI.Themes.WPF;component/Themes/Themes.DeepDark.xaml",
                        UriKind.RelativeOrAbsolute
                    )
                }
            },
            {
                "LightDark",
                new ResourceDictionary
                {
                    Source = new Uri(
                        @"/FireUI.Themes.WPF;component/Themes/Themes.LightDark.xaml",
                        UriKind.RelativeOrAbsolute
                    )
                }
            }
        };
    }

    public void ApplyTheme(string name)
    {
        if (!_themes.ContainsKey(name))
        {
            return;
        }

        foreach (var kvp in _themes)
        {
            Application.Current.Resources.MergedDictionaries.Remove(kvp.Value);
        }

        Application.Current.Resources.MergedDictionaries.Add(_themes[name]);
    }

    public IEnumerable<string> GetThemes() => _themes.Keys;
}